<template>
  <div class="chooseSettle">
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      @closed="handleClose"
    >
      <el-alert :title="alertTitle" type="error" :closable="false"> </el-alert>
      <div class="ccui-advanced-search-wrapper">
        <el-search
          :formProp="formData"
          @search="search"
          :isShowSearch="isShowSearch"
          class="ccui-highsearch"
          :selectClear="true"
          :spoNum="2"
          @resetForm="resetForm"
        >
          <template slot="search">
            <el-input
              v-model="formData.warehouseName"
              clearable
              searchLabel="仓库名称"
              placeholder="请输入仓库名称模糊查询"
              @blur="handleTrim('warehouseName')"
            ></el-input>
            <el-input
              v-model="formData.warehouseCode"
              clearable
              searchLabel="仓库编号"
              placeholder="请输入仓库编号模糊查询"
              @blur="handleTrim('warehouseCode')"
            ></el-input>
            <el-input
              v-model="formData.warehousePhone"
              clearable
              searchLabel="联系电话"
              placeholder="请输入联系电话模糊查询"
              @blur="handleTrim('warehousePhone')"
              maxlength="11"
            ></el-input>
            <el-input
              v-model="formData.warehousePlace"
              clearable
              searchLabel="库存地点"
              placeholder="请输入库存地点模糊查询"
              @blur="handleTrim('warehousePlace')"
            ></el-input>
          </template>
          <!-- 表单高级搜索 -->
          <el-input
            v-model="formData.warehouseName"
            clearable
            searchLabel="仓库名称"
            placeholder="请输入仓库名称模糊查询"
            @blur="handleTrim('warehouseName')"
            slot="searchItem1"
          ></el-input>
          <el-input
            v-model="formData.warehouseCode"
            clearable
            searchLabel="仓库编号"
            placeholder="请输入仓库编号模糊查询"
            @blur="handleTrim('warehouseCode')"
            slot="searchItem2"
          ></el-input>
          <el-input
            v-model="formData.warehousePlace"
            clearable
            searchLabel="库存地点"
            placeholder="请输入库存地点模糊查询"
            @blur="handleTrim('warehousePlace')"
            slot="searchItem4"
          ></el-input>
          <el-input
            v-model="formData.warehousePhone"
            clearable
            searchLabel="联系电话"
            placeholder="请输入联系电话模糊查询"
            @blur="handleTrim('warehousePhone')"
            maxlength="11"
            slot="searchItem3"
          ></el-input>
        </el-search>
        <!-- 搜索条件结束 -->
        <div class="ccui-multifunctional-table-wrapper">
          <el-table
            :dataObj="singleSelectData"
            :data="purchaseListList"
            class="ccui-form-child-table"
            border
            width="600px"
            style="margin-bottom: 20px"
            max-height="800px"
          >
            <el-table-column
              show-overflow-tooltip
              label="序号"
              type="index"
              align="center"
            />

            <el-table-column
              show-overflow-tooltip
              prop="warehouseCode"
              label="仓库编号"
            >
            </el-table-column>

            <el-table-column
              show-overflow-tooltip
              prop="warehouseName"
              label="仓库名称"
            >
            </el-table-column>

            <el-table-column
              show-overflow-tooltip
              prop="warehousePlace"
              label="库存地点"
            >
            </el-table-column>

            <el-table-column
              show-overflow-tooltip
              prop="warehousePhone"
              label="联系电话"
            >
            </el-table-column>

            <el-table-column label="操作" width="90">
              <template slot-scope="{ row }">
                <el-button size="mini" type="text" @click="handlecheck(row)"
                  >选择</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- <div class="table-footer" style="height: 35px">
            <div id="ccui-paging">
              <el-pagination
                :total="totalNum"
                :page-size="getLocalPageSize()"
                :current-page="formDataSearch.pageNo"
                :page-sizes="[10, 20, 50, 100, 200, 500]"
                background
                layout="total, sizes, prev, pager, next, jumper"
                popper-class="ccui-paging-page-size-popper"
                @prev-click="handlePrev"
                @next-click="handleNext"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
              <el-button
                class="ccui-pagination-btn"
                size="mini"
                type="default"
                @click="handleChangeSize('none')"
                >确定</el-button
              >
            </div>
          </div> -->
      </div>
    </el-dialog>
  </div>
</template>
<script>
// import { getSupplierData } from "@/basa/api";

import { listScWarehouse } from "@/app/inventoryManagement/components/api";
import { setSessionItem, getSessionItem } from "@/basa/utils";

export default {
  props: {
    partyAId: {
      type: Number
    },
    recordsTotal: {
      type: Number
    },
    reportInOrgName: {
      type: String
    },
    reportInOrgId: {
      type: Number
    },
    isTrue: {
      type: Boolean
    }
  },
  name: "warehouseDialog",
  data() {
    return {
      title: "选择仓库",
      alertTitle: "如需维护仓库信息，请去仓库维护功能菜单进行操作!",
      // 招标结果关联弹窗相关变量 start
      // formDate: {
      //   warehouseCode: "",
      //   warehouseName: "",
      //   warehousePlace: "",
      //   warehousePhone: "",
      //   orgid: "",
      //   materialCode: "",
      // },
      purchaseListList: [],
      singleSelectData: [],
      dialogVisible: false,
      formData: {
        warehouseName: "",
        warehouseCode: "",
        warehousePhone: "",
        warehousePlace: ""
      },
      formDataSearch: {
        warehouseName: "",
        warehouseCode: "",
        warehousePhone: "",
        warehousePlace: ""
      },
      totalNum: 0,
      isShowSearch: true
      // 招标结果关联弹窗相关变量 end
    };
  },
  watch: {},
  methods: {
    showContractList() {
      this.dialogVisible = true;
      this.getContractList(this.formData);
    },
    getContractList(data) {
      listScWarehouse({
        ...data,
        reportInOrgId: this.reportInOrgId
      }).then(res => {
        this.purchaseListList = res.data.data;
      });
    },
    //数据
    // getSupplierData() {
    //   getSupplierData(this.formDate).then(res => {
    //     this.singleSelectData = res.data.data.rows;
    //     this.singleSelectPageTotal = res.data.data.recordsTotal;
    //     console.log(this.singleSelectPageTotal);
    //   });
    // },
    handlecheck(row) {
      this.$emit("numrow", row);
      this.dialogVisible = false;
    },
    handleClose() {},
    //去空格
    handleTrim(key) {
      if (this.formData[key]) {
        this.$set(
          this.formData,
          key,
          this.formData[key].replace(/(^\s*)|(\s*)$/g, "")
        );
      }
    },
    //重置
    resetForm() {
      console.log("赵", 22222);
      this.$set(this.formData, "warehouseName", "");
      this.$set(this.formData, "warehouseCode", "");
      this.$set(this.formData, "warehousePhone", "");
      this.$set(this.formData, "warehousePlace", "");

      console.log(this.formData.warehousePhone);
    },
    // 分页
    // 上一页
    handlePrev() {},
    // 下一页
    handleNext() {},
    //  显示条数更改
    handleSizeChange(val) {
      this.formDataSearch.pageNo = 1;
      this.formDataSearch.pageSize = val;
      setSessionItem("pageSize", this.tableName, val);
      this.getContractList(this.formDataSearch);
    },
    //翻页确定
    handleChangeSize() {
      this.getContractList();
    },
    // 获取默认条数
    getLocalPageSize() {
      return (
        getSessionItem("pageSize", this.tableList.financialWriteOffListAll) ||
        10
      );
    },
    // 当前页码更改
    handleCurrentChange(val) {
      // 跳转翻页都会调这个方法
      this.formDataSearch.pageNo = val;
      this.getContractList(this.formDataSearch);
    },
    // 高级搜索展开按钮
    search(searchData) {
      let regexp = /^\d{1,11}$/;
      if (searchData.warehousePhone) {
        if (regexp.test(searchData.warehousePhone)) {
          this.formDataSearch = JSON.parse(JSON.stringify(searchData));
          this.formDataSearch.reportOrgId = getSessionItem("userInfo", "orgId");
          this.formDataSearch.pageNo = 1;
          this.formDataSearch.isShowPageLoading = true;
          this.formDataSearch.pageSize = this.getLocalPageSize();
          this.getContractList(this.formDataSearch);
        } else {
          this.$message({
            message: "请输入正确联系电话",
            type: "error",
            showClose: true,
            ccuiCustom: true,
            duration: 8000
          });
        }
      } else {
        this.formDataSearch = JSON.parse(JSON.stringify(searchData));
        this.formDataSearch.reportOrgId = getSessionItem("userInfo", "orgId");
        this.formDataSearch.pageNo = 1;
        this.formDataSearch.isShowPageLoading = true;
        this.formDataSearch.pageSize = this.getLocalPageSize();
        this.getContractList(this.formDataSearch);
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.chooseSettle {
  display: inline-block;
}
/deep/.el-single-select
  .el-dialog__wrapper
  .el-dialog
  .el-dialog__body
  .el-dialog-box
  .dialog-top {
  justify-content: space-between;
}
/deep/ .el-table__body-wrapper {
  max-height: 230px !important;
}
/deep/.label {
  display: inline-block;
  width: 130px !important;
  text-align: right;
}
/deep/ .el-dialog__footer {
  border-top: none;
}
/deep/ .el-table td,
.el-table th {
  padding: 5px 0 !important;
}
/deep/ .disabledBtn {
  // border: 1px solid #999 !important;
  span {
    color: #999 !important;
  }
}

/deep/ .ccui-advanced-search-wrapper .el-search {
  margin-top: 15px;
}
/deep/.el-form-item {
  margin-bottom: 15px !important;
}
/deep/.el-search .el-searchs {
  float: none;
}
/deep/.el-searchs-box {
  margin: 0 auto;
}
/deep/ .el-dialog__header .el-dialog__title {
  line-height: 30px !important;
}
</style>
